import React, { Component, PropTypes } from "react";
import { messages } from "share/common";
import { Button } from 'antd'
import borrowService from "../../borrow-and-return.service";

class BtnPrint extends Component {

  state = {
    loading: false
  };

  handlePrint = () => {
    const { info } = this.context;
    this.setState({ loading: true });
    borrowService.printLoanApplication(info.loanBillOID).then(res => {
      this.setState({ loading: false });
      window.open(res.data.link, '_blank')
    }).catch(() => {
      this.setState({ loading: false })
    })
  };

  render() {
    const { loading } = this.state;
    return (
      <Button type="primary" loading={loading} onClick={this.handlePrint}>
        {messages('common.print')/*打印*/}
      </Button>
    )
  }

  static contextTypes = {
    info: PropTypes.object
  }

}

export default BtnPrint
